#pragma once

// BlockPuzzle game class
//

//#define DEBUG_MODE

#include <conio.h>
#include "Map.h"
#include <time.h>

#define MAIN_X 10
#define MAIN_Y	5

#define TITLE_X 25
#define TITLE_Y	8

#define NEXT_TETRAD_X	37
#define NEXT_TETRAD_Y	12
#define NUM_LINES_TO_CLEAR	4

#define TIME_PER_AUTOMOVE	1000
#define TIME_PER_ITERATION	10

#define SCORE_PER_ROW 100

#define AUTO_MOVE	-1

#define NUM_TETRADS 7

#define TETRAD_ELEMENT		'*'
#define PERMANENT_ELEMENT	'#'
#define EMPTY_ELEMENT		'.'

static char * gMainMapFile = "MainMap.txt";
static char * gTetradFiles[NUM_TETRADS] = 
{
	"Tetrad_O.txt",
	"Tetrad_I.txt",
	"Tetrad_S.txt",
	"Tetrad_T.txt",
	"Tetrad_Z.txt",
	"Tetrad_r.txt",
	"Tetrad_L.txt",
};

enum eInputMessage
{
	INPUT_NONE = 100,
	INPUT_MOVELEFT,
	INPUT_MOVERIGHT,
	INPUT_MOVEUP,
	INPUT_MOVEDOWN,
	INPUT_ROTATECW,
	INPUT_ROTATECCW
};

class BlockPuzzle
{
private:
	char			mUserInput;
	int				mCursorX;
	int				mCursorY;
	int				mMainX;
	int				mMainY;
	Map				mMainMap;
	Map				mTetrad;
	Map				mNextTetrad;
	eInputMessage	mLastInput;
	int				mScore;

public:
	BlockPuzzle() : mUserInput(0), mCursorX(0), mCursorY(0), mMainX(MAIN_X), mMainY(MAIN_Y), mLastInput(INPUT_NONE) 
	{
		// seed the RNG
		srand(time(NULL));
	}
	~BlockPuzzle() {}

	void Init();
	void Run();
	void Update();
	void Render();
	void Quit();
	bool CheckCollisions(bool skipPermanance = false);
	void PickTetrad(bool initialized = false);
	void MakeTetradPermanent();
	void DestroyFullRows();
	void RestartGame();
};